package com.sfilyh.servelt;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sfilyh.util.DBUtil;
import com.sfilyh.util.StringUtils;

@WebServlet("/post")
public class PostServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String article =  request.getParameter("article");
		String pid  = request.getParameter("pid");
		if(pid == null || "".equals(pid)) pid = "0";
		String content = request.getParameter("content");
		String guestname = request.getParameter("guestname");
		String guestemail = request.getParameter("guestemail");
		String guestblog = request.getParameter("guestblog");
		
		if(!StringUtils.validate(article,content,guestname,guestemail,guestblog)){
			
		}
		String insertSql = "insert into tb_post(pid,articleid,guestname,guestemail,guestblog,content) " +
				" values (?,?,?,?,?,?)";
		DBUtil.update(insertSql,Integer.parseInt(pid),article,guestname,guestemail,guestblog,content);
		
		response.sendRedirect(request.getContextPath()+"/view?id="+article);
	}
	
	

}
